From 5c33c7b55c56c8eedd72a242f9f97925f6b04591 Mon Sep 17 00:00:00 2001 From: "iap10@labyrinth.cl.cam.ac.uk" Date: Sun, 30 Nov 2003 23:02:25 +0000 Subject: [PATCH] bitkeeper revision 1.637 (3fca7701y4KoOnx1zp_ccoR7G153xg) Add dom0 op to pin a domain to a specified CPU (or -1 to unpin). This function is currently only supported for domains that have been 'created' but not 'built' or 'started'. --- .rootkeys | 1 + BitKeeper/etc/ignore | 10 ++++++++ tools/examples/pincpu.py | 16 +++++++++++++ tools/xc/lib/xc_domain.c | 12 ++++++++++ tools/xc/py/Xc.c | 28 +++++++++++++++++++++++ tools/xc/py/XenoUtil.py | 14 ++++++++++++ xen/common/dom0_ops.c | 33 +++++++++++++++++++++++++++ xen/include/hypervisor-ifs/dom0_ops.h | 16 +++++++++++++ xen/include/xeno/sched.h | 3 ++- 9 files changed, 132 insertions(+), 1 deletion(-) create mode 100755 tools/examples/pincpu.py diff --git a/.rootkeys b/.rootkeys index 4e135eadd2..fe17b6d2ab 100644 --- a/.rootkeys +++ b/.rootkeys @@ -42,6 +42,7 @@ 3fbe2f12OPAkzIUtumU3wRAihnhocQ tools/examples/createlinuxdom.py 3fbe2f12dZbmXLlgQdMgkmnSUj23AQ tools/examples/destroydom.py 3fbe2f12ltvweb13kBSsxqzZDAq4sg tools/examples/listdoms.py +3fca7700PVj36cZObaFZlQicRiw1pQ tools/examples/pincpu.py 3fbe2f12Bnt8mwmr1ZCP6HWGS6yvYw tools/examples/stopdom.py 3f776bd2Xd-dUcPKlPN2vG89VGtfvQ tools/misc/Makefile 3f6dc136ZKOjd8PIqLbFBl_v-rnkGg tools/misc/miniterm/Makefile diff --git a/BitKeeper/etc/ignore b/BitKeeper/etc/ignore index d68573efe9..8ceb5a914c 100644 --- a/BitKeeper/etc/ignore +++ b/BitKeeper/etc/ignore @@ -513,3 +513,13 @@ xen/drivers/scsi/aic7xxx/aic79xx_osm.o xen/drivers/scsi/aic7xxx/aic79xx_osm_pci.o xen/drivers/scsi/aic7xxx/aic79xx_pci.o xen/drivers/scsi/aic7xxx/aic79xx_proc.o +tools/xc/lib/xc_bvtsched.o +tools/xc/lib/xc_domain.o +tools/xc/lib/xc_linux_build.o +tools/xc/lib/xc_linux_restore.o +tools/xc/lib/xc_linux_save.o +tools/xc/lib/xc_misc.o +tools/xc/lib/xc_private.o +tools/xc/lib/xc_vbd.o +tools/xc/lib/xc_vif.o +xen/xen.s diff --git a/tools/examples/pincpu.py b/tools/examples/pincpu.py new file mode 100755 index 0000000000..d978067d72 --- /dev/null +++ b/tools/examples/pincpu.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +# +# Destroy specified domain. +# + +import Xc, sys, re + +xc = Xc.new() + +if len(sys.argv) < 3: + print "Specify a domain identifier and CPU" + sys.exit() + +xc.domain_pincpu( dom=int(sys.argv[1]), cpu=int(sys.argv[2])) + diff --git a/tools/xc/lib/xc_domain.c b/tools/xc/lib/xc_domain.c index f120791848..5601fb485c 100644 --- a/tools/xc/lib/xc_domain.c +++ b/tools/xc/lib/xc_domain.c @@ -57,6 +57,18 @@ int xc_domain_destroy(int xc_handle, return do_dom0_op(xc_handle, &op); } +int xc_domain_pincpu(int xc_handle, + unsigned int domid, + int cpu) +{ + dom0_op_t op; + op.cmd = DOM0_PINCPUDOMAIN; + op.u.pincpudomain.domain = domid; + op.u.pincpudomain.cpu = cpu; + return do_dom0_op(xc_handle, &op); +} + + int xc_domain_getinfo(int xc_handle, unsigned int first_domid, unsigned int max_doms, diff --git a/tools/xc/py/Xc.c b/tools/xc/py/Xc.c index 05309b5daf..0676bd137b 100644 --- a/tools/xc/py/Xc.c +++ b/tools/xc/py/Xc.c @@ -95,6 +95,26 @@ static PyObject *pyxc_domain_destroy(PyObject *self, return PyInt_FromLong(ret); } +static PyObject *pyxc_domain_pincpu(PyObject *self, + PyObject *args, + PyObject *kwds) +{ + XcObject *xc = (XcObject *)self; + + unsigned int dom; + int cpu, ret; + + static char *kwd_list[] = { "dom", "cpu", NULL }; + + if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list, + &dom, &cpu) ) + return NULL; + + ret = xc_domain_pincpu(xc->xc_handle, dom, cpu); + + return PyInt_FromLong(ret); +} + static PyObject *pyxc_domain_getinfo(PyObject *self, PyObject *args, PyObject *kwds) @@ -507,6 +527,14 @@ static PyMethodDef pyxc_methods[] = { " force [int, 0]: Bool - force immediate destruction?\n\n" "Returns: [int] 0 on success; -1 on error.\n" }, + { "domain_pincpu", + (PyCFunction)pyxc_domain_pincpu, + METH_VARARGS | METH_KEYWORDS, "\n" + "Pin a domain to a specified CPU.\n" + " dom [int]: Identifier of domain to be destroyed.\n" + " force [int, -1]: CPU to pin to, or -1 to unpin\n\n" + "Returns: [int] 0 on success; -1 on error.\n" }, + { "domain_getinfo", (PyCFunction)pyxc_domain_getinfo, METH_VARARGS | METH_KEYWORDS, "\n" diff --git a/tools/xc/py/XenoUtil.py b/tools/xc/py/XenoUtil.py index 1a135bfdff..dfbcabc800 100644 --- a/tools/xc/py/XenoUtil.py +++ b/tools/xc/py/XenoUtil.py @@ -128,3 +128,17 @@ def setup_vfr_rules_for_vif(dom,vif,addr): ' proto=any\n' ) os.close( fd ) return None + +def addr_of_iface( iface ): + fd = os.popen( '/sbin/ifconfig '+iface ) + lines = fd.readlines() + for line in lines: + m = re.search( 'inet addr:([0-9.]+)', line ) + if m: + return m.group(1) + return None + +def add_to_ip( ip, off ): + l = string.split(ip,'.') + return '%s.%s.%s.%d' % ( l[0],l[1],l[2],string.atoi(l[3])+off ) + diff --git a/xen/common/dom0_ops.c b/xen/common/dom0_ops.c index 344a65f83a..5f5e803c5a 100644 --- a/xen/common/dom0_ops.c +++ b/xen/common/dom0_ops.c @@ -184,6 +184,39 @@ long do_dom0_op(dom0_op_t *u_dom0_op) } break; + case DOM0_PINCPUDOMAIN: + { + struct task_struct * p = find_domain_by_id(op.u.pincpudomain.domain); + int cpu = op.u.pincpudomain.cpu; + ret = -EINVAL; + if ( p != NULL ) + { + if( cpu == -1 ) + p->cpupinned = 0; + else + { + /* For the moment, we are unable to move running + domains between CPUs. (We need a way of cleanly stopping + running domains). For now, if we discover the domain is + running then cowardly bail out with ENOSYS */ + + if(p->flags & PF_CONSTRUCTED) + ret = -ENOSYS; + else + { + cpu = cpu % smp_num_cpus; + p->processor = cpu; + p->cpupinned = 1; + } + } + + ret = 0; + put_task_struct(p); + } + + } + break; + case DOM0_BVTCTL: { unsigned long ctx_allow = op.u.bvtctl.ctx_allow; diff --git a/xen/include/hypervisor-ifs/dom0_ops.h b/xen/include/hypervisor-ifs/dom0_ops.h index 2c3d12ab78..045e4ad70e 100644 --- a/xen/include/hypervisor-ifs/dom0_ops.h +++ b/xen/include/hypervisor-ifs/dom0_ops.h @@ -197,6 +197,17 @@ typedef struct dom0_readconsole_st unsigned int cmd; } dom0_readconsole_t; +/* + * Pin Domain to a particular CPU (use -1 to unpin) + */ +#define DOM0_PINCPUDOMAIN 20 +typedef struct dom0_pincpudomain_st +{ + /* IN variables. */ + unsigned int domain; + int cpu; /* -1 implies unpin */ +} dom0_pincpudomain_t; + typedef struct dom0_op_st { unsigned long cmd; @@ -218,7 +229,12 @@ typedef struct dom0_op_st dom0_debug_t debug; dom0_settime_t settime; dom0_readconsole_t readconsole; + dom0_pincpudomain_t pincpudomain; } u; } dom0_op_t; + + + + #endif diff --git a/xen/include/xeno/sched.h b/xen/include/xeno/sched.h index b4a7520a64..736201446a 100644 --- a/xen/include/xeno/sched.h +++ b/xen/include/xeno/sched.h @@ -102,7 +102,8 @@ struct task_struct struct list_head run_list; int has_cpu; int state; /* current run state */ - + int cpupinned; /* true if pinned to curent CPU */ + s_time_t lastschd; /* time this domain was last scheduled */ s_time_t cpu_time; /* total CPU time received till now */ s_time_t wokenup; /* time domain got woken up */ -- 2.30.2